//Mobile phone
var preg = /^1(3[0-9]|4[57]|5[0-35-9]|7[0135678]|8[0-9])\d{8}$/;
//Fixed telephone
var greg = /^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/;
//Email 
var ereg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
//ID
var ireg = /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/;
//Verification Code
var creg = /^\d{4}$/;
//Bank card;
var breg = /^(\d{16}|\d{19})$/;
//Letters and numbers
var lreg = /[0-9]+[a-zA-Z]+[0-9a-zA-Z]*|[a-zA-Z]+[0-9]+[0-9a-zA-Z]*/;
//url
var ureg = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
//time
//var treg = /^([0-1]?[0-9]|2[0-3]):([0-5][0-9])$/;
var treg = /^([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/;

//submit true
function submitT() {
	$(".submit").attr("disabled", false);
	$(".submit").css({
		"background": "linear-gradient(to top, rgb(68, 129, 235) 0%, rgb(4, 190, 254) 100%)",
		"cursor": "pointer"
	});

	$(".submit").hover(function() {
		$(this).css({
			"background": "linear-gradient(to top, rgb(68, 129, 235) 0%, rgb(4, 190, 254) 100%)",
		});
	}, function() {
		$(this).css({
			"background": "linear-gradient(to top, rgb(68, 129, 235) 0%, rgb(4, 190, 254) 100%)",
		});
	});
}

//submit false
function submitF() {
	$(".submit").attr("disabled", true);
	$(".submit").css({
		"background": "#ccc",
		"cursor": 'not-allowed',
	});
}

//url
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if(r != null)
		return unescape(r[2]);
	return null;
}

//lay.msg
function diaMsg(text, num) {
	layer.msg(text, {
		icon: num,
		time: 2500,
	});
}

//tips
function diaTips(text, ele) {
	layer.tips(text, ele, {
		tips: [1, "red"],
		time: 3000
	});
}

//loding
function diaLoding(text) {
	layer.msg(text, {
		icon: 16,
		shade: 0.31,
		time: 0,
		area: ["160px", ""]
	});
}

function diaLodend() {
	layer.closeAll();
}

//error
function diaError() {
	layer.msg('网络异常，请刷新重试！', {
		icon: 2,
		shade: 0.31,
		time: 3500,
		area: ["240px", ""]
	});
}

//empty
function emShow(text) {
	$(".empty").show();
	$(".empty span").html(text);
	$(".zxf_pagediv").hide();
}

function emHide(text) {
	$(".empty").hide();
	$(".empty span").html("");
}

//json
var QUAN = "/";
var LIST_CATEGORY_URL = QUAN + "categorys";
var LIST_LIST_URL = QUAN + "list";
var ARTICLE_DOWNLOAD_URL = QUAN + "download";

//ajax
function ajaxPost(ajurl, ajdata, ajsuccess, ajerror, ajtime, ajtype) {

	if(ajtime == "" || ajtime == undefined) {
		ajtime = 15000;
	}
	if(ajtype == "" || ajtype == undefined) {
		ajtype = "post"
	}

	$.ajax({
		type: ajtype,
		url: ajurl,
		async: true,
		data: ajdata,
		timeout: ajtime,
		xhrFields: {
			withCredentials: true
		},
		success: function(data) {

			if(ajsuccess == "" || ajsuccess == undefined) {
				diaMsg("网络异常，请刷新重试", 2);
			} else {
				ajsuccess(data);
			}

		},
		error: function(data) {
			if(ajerror == "" || ajerror == undefined) {
				diaMsg("网络异常，请刷新重试", 2)
			} else {
				ajerror(data)
			}
		}

	});

}

//ajerror
function ajerror(data) {
	//close lay
	diaLodend();
	//error open
	diaError();
}

//error code
function check_code(err_msg) {
	//close lay
	diaLodend();
	if(err_msg == "登录信息不存在") {
		diaMsg("登录信息不存在", 2);
		setTimeout(function() {
			window.location.href = "login.jsp";
		}, 2500);
	} else {
		diaMsg(err_msg, 2);
		submitT();
	}

}

function keyNum(obj) {
	obj.value = obj.value.replace(/\D/g, '');
}

keyPri();

function keyPri() {
	$(".package-price").keypress(function() {
		var reg = $(this).val().match(/\d+(\.\d{0,2})?/);
		var txt = '';
		if(reg != null) {
			txt = reg[0];
		}
		$(this).val(txt);
	}).change(function() {
		$(this).keypress();
	});
}

//
$(".form-close,.form-mask").click(function() {
	$(".form-mask").fadeOut();
	$(".add-form,.userInfo-details").hide();

	formInit();
});

function formInit() {
	$(".add-form input,.add-form #form-text").not(".submit").val("");
	$(".radio .r-big").css("border-width", "1px").attr("num", "0");
	$(".radio .radio-1").eq(0).find(".r-big").css("border-width", "5px").attr("num", "1");
}

function showMask(text) {
	$(".maskk").fadeIn();
	$(".mask-content").fadeIn().find("p").text(text);
}

function getDay(day) {
	var today = new Date();

	var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;

	today.setTime(targetday_milliseconds); //注意，这行是关键代码    

	var tYear = today.getFullYear();
	var tMonth = today.getMonth();
	var tDate = today.getDate();
	//加0
	tMonth = doHandleMonth(tMonth + 1);
	tDate = doHandleMonth(tDate);
	return tYear + "-" + tMonth + "-" + tDate;
}

function doHandleMonth(month) {
	var m = month;
	if(month.toString().length == 1) {
		m = "0" + month;
	}
	return m;
}
var ndata = getDay(0);
var ydata = getDay(-1);
var qdata = getDay(-2);

var _sysTime;

function sTime(s) {
	return s < 10 ? '0' + s : s;
}

function systemTime() {
	var myDate = new Date();
	var year = myDate.getFullYear();
	var month = myDate.getMonth() + 1;
	var date = myDate.getDate();
	var h = myDate.getHours();
	var m = myDate.getMinutes();
	var s = myDate.getSeconds();

	_sysTime = sTime(h) + ':' + sTime(m) + ":" + sTime(s);

}

$(".nav-mask").click(function() {
	$(this).hide();
	$("#ul1 div:gt(0),#ul2 div:gt(0),#ul3 div:gt(0),#ul4 div:gt(0)").slideUp(200);
});

//
//ajaxPost(USERINFO_URL, "", adifsucc, ajerror, 15000);
//var _usernick, _taskNum;
//
//function adifsucc(data) {
//	var error_code = data.code;
//	if(error_code == 1) {
//		var data1 = data.data;
//		_usernick = data1.username;
//		_taskNum = data1.taskNum;
//		$(".a-username span").html(_usernick);
//		$(".a-b-center .a-b-span2").html(_taskNum);
//	}
//}
//
//$(".a-exit").click(function() {
//	diaLoding("退出中...");
//	ajaxPost(LOGIN_OUT_URL, "", loosucc, ajerror, 15000);
//});
//
//function loosucc(data) {
//	var error_code = data.code;
//	var error_msg = data.msg;
//	if(error_code == 1) {
//		setTimeout(function() {
//			diaMsg("退出成功", 1);
//		}, 1000);
//		setTimeout(function() {
//			window.location.href = "login.jsp";
//		}, 2500);
//	} else {
//		check_code(error_msg);
//	}
//}